import Vue from 'vue'
import Router from 'vue-router'

/**
 * 有2个页面，代表着有2个组件，
 * 需要在下面“export” 里用数组的形式把它们配起来
 */
import Main from '../views/Main'
import Login from '../views/Login'
import UserCenter from "../components/UserCenter";
import TaskList from "../components/TaskList";
import BrokerList from "../components/BrokerList";
import TaskManagement from "../components/TaskManagement";
import PlacardEdit from "../components/PlacardEdit";
import TaskAdminList from "../components/TaskAdminList";



/**
 * 重写路由的push方法
 */
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error=> error)
}

Vue.use(Router);

export default new Router({
  routes: [
    {name: 'Home',path: '/',component: Login},
    {name: 'Login',path: '/login',component: Login},
    {name: 'Main',path: '/main',component: Main,
      children: [
        // 以“/”开头的嵌套路径会被当作根路径，所以子路由上不用加“/”;
        // 在生成路由时，主路由上的path会被自动添加到子路由之前，所以子路由上的path不用在重新声明主路由上的path
        {name: 'UserCenter',path: 'userCenter',component: UserCenter},
        {name: 'TaskList',path: 'taskList',component: TaskList},
        {name: 'BrokerList',path: 'brokerList',component: BrokerList},
        {name: 'PlacardEdit',path: 'placardEdit',component: PlacardEdit},
        {name: 'TaskAdminList',path: 'taskAdminList',component: TaskAdminList},
        {name: 'TaskManagement',path: 'taskManagement',component: TaskManagement},
      ]
    }
  ]
})
